<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/common.jsp"%>
<title>商品属性关系添加</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form" action="" method="post">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>属性名称1：</label>
            <div class="formControls col-xs-8 col-sm-8">
            	<select id="skuName1" name="skuName1" class="select" required>
            		<c:forEach items="${skus}" var="sku">
            			<option value="${sku.name}">${sku.name}</option>
            		</c:forEach>
				</select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>属性值1：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" placeholder=" 如果没有，请填'默认'" value="" id="skuValue1" name="skuValue1" required>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">属性名称2：</label>
            <div class="formControls col-xs-8 col-sm-8">
            	<select id="skuName2" name="skuName2" class="select">
            		<option value="">无</option>
            		<c:forEach items="${skus}" var="sku">
            			<option value="${sku.name}">${sku.name}</option>
            		</c:forEach>
				</select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">属性值2：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" value="" id="skuValue2" name="skuValue2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>库存：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" value="" placeholder="" id="stock" name="stock" required="true">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>价格(元)：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" value="" placeholder="" id="price" name="price" required="true">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-8 col-xs-offset-4 col-sm-offset-3">
                <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
            </div>
        </div>
    </form>
</article>

<script type="text/javascript">
$(document).ready(function () {
	var productId = "${productId}";
	 $('#form').bind('submit', function () {
		var skuName1 = $("#skuName1").val();
		var skuValue1 = $("#skuValue1").val();
		var skuName2 = $("#skuName2").val();
		var skuValue2 = $("#skuValue2").val();
		var stock = $("#stock").val();
		var price = $("#price").val();
		$.ajax({
			type : 'POST',
			url : ctx + '/productManage/addProductSkuRelation.do',
			data : {
				productId : productId,
				skuName1 : skuName1,
				skuValue1 : skuValue1,
				skuName2 : skuName2,
				skuValue2 : skuValue2,
				stock : stock,
				price : price
			},
			dataType : 'json',
			timeout : 30000,
			context : $('body'),
			success : function(data) {
				if (data.code == "ok") {
                    layer.msg("保存成功!", {icon: 6, time: 1000}, function () {
                    	layer_close();
                    });
				} else {
					 layer.msg(data.msg, {icon: 5, time: 2000});
				}
			},
			error : function(xhr, type) {
				layer.msg('保存失败!', {icon: 5, time: 2000});
			}
		});
		  return false;
	 });
});
</script>
</body>
</html>